package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.CsChildPreferenceDto;
import cn.tedu.eb_film.pojo.dto.UpdateCsChildPreferenceDto;
import cn.tedu.eb_film.pojo.entity.CsChildPreference;
import cn.tedu.eb_film.pojo.vo.CsChildPreferenceVo;
import cn.tedu.eb_film.service.CsChildPreferenceService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/CsChildPreference")
@Api(tags = "小孩优惠")
public class CsChildPreferenceController {

    @PostMapping("/{id:[0-9]+}/enable")
    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 220)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "int")
    })
    public JsonResult<Void> setEnable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Integer id) {
        log.debug("开始处理【启用优惠政策】的请求，参数：{}", id);
        csChildPreferenceService.setEnable(id);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/disable")
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 221)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "int")
    })
    public JsonResult<Void> setDisable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Integer id) {
        log.debug("开始处理【禁用优惠政策】的请求，参数：{}", id);
        csChildPreferenceService.setDisable(id);
        return JsonResult.ok();
    }


    @Autowired
    CsChildPreferenceService csChildPreferenceService;

    /**
     * 添加单个小孩优惠
     * @return
     */
    @PostMapping("/AddCsChildPreference")
    public JsonResult<Void> AddCsChildPreference(CsChildPreferenceDto csChildPreferenceDto){
        csChildPreferenceService.AddCsChildPreference(csChildPreferenceDto);
        return JsonResult.ok();
    }

    /**
     * 批量添加小孩优惠
     * @param list
     * @return
     */
    @PostMapping("/AddCsChildPreferenceList")
    public JsonResult<Void> AddCsChildPreferenceList(List<CsChildPreference> list){
        csChildPreferenceService.AddCsChildPreferenceList(list);
        return JsonResult.ok();
    }

    /**
     * 根据id删除小孩优惠
     * @param id
     * @return
     */
    @PostMapping("/{id:[0-9]+}/deleteCsChildPreferenceById")
    public JsonResult<Void> deleteCsChildPreferenceById( @PathVariable Long id){
        csChildPreferenceService.deleteCsChildPreferenceById(id);
        return JsonResult.ok();
    }

    /**
     * 根据ids批量删除小孩优惠
     * @param list
     * @return
     */
    @PostMapping("/deleteCsChildPreferenceByIds")
    public JsonResult<Void> deleteCsChildPreferenceById(List<Long> list){
        csChildPreferenceService.deleteCsChildPreferenceByIds(list);
        return JsonResult.ok();
    }

    /**
     * 统计小孩优惠
     * @return
     */
    @GetMapping("/countCsChildPreference")
    public JsonResult<Void> countCsChildPreference(){
        csChildPreferenceService.countCsChildPreference();
        return JsonResult.ok();
    }

    /**
     * 通过id获取小孩优惠
     * @param id
     * @return
     */
    @PostMapping("/{id:[0-9]+}/getCsChildPreferenceById")
    public JsonResult<CsChildPreferenceVo> getCsChildPreferenceById(@PathVariable Integer id){
        CsChildPreferenceVo csChildPreferenceById = csChildPreferenceService.getCsChildPreferenceById(id);
        return JsonResult.ok(csChildPreferenceById);
    }

    /**
     * 获取小孩优惠集合
     * @return
     */
    @GetMapping("/getCsChildPreferenceList")
    public JsonResult<List<CsChildPreferenceVo>> getCsChildPreferenceList(){
        List<CsChildPreferenceVo> list = csChildPreferenceService.getCsChildPreferenceList();
        return JsonResult.ok(list);
    }

    /**
     * 修改小孩优惠
     * @return
     */
    @PostMapping("/updateCsChildPreference")
    public JsonResult<Void> updateCsChildPreference(UpdateCsChildPreferenceDto updateCsChildPreferenceDto){
        csChildPreferenceService.updateCsChildPreference(updateCsChildPreferenceDto);
        return JsonResult.ok();
    }

}
